package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.entity.Schedule;
import com.tianya.domain.entity.Score;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.domain.vo.ScoreVO;
import com.tianya.service.ScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author TianYaGuoKe
 * @date 2025/5/27 9:50
 * @description ScoreController
 */
@Api("成绩管理")
@RestController
@RequestMapping("/score")
public class ScoreController {

    @Resource
    private ScoreService scoreService;


     @ApiOperation("分页获取成绩")
     @GetMapping("/page")
    public Results<PageResultVO<ScoreVO>>  pageScore(@RequestParam(defaultValue = "1") Integer pageNum,
                                                     @RequestParam(defaultValue = "10") Integer pageSize,
                                                     Score  scoreRequestDTO) {
        PageResultVO<ScoreVO> pageResultVO = scoreService.pageScore(pageNum, pageSize, scoreRequestDTO);
        return Results.success(pageResultVO);
    }

    @ApiOperation("根据学生ID查询成绩")
    @GetMapping("/list/{studentId}")
    public Results<List<ScoreVO>> list(@RequestParam Long studentId) {
        List<ScoreVO> list = scoreService.listByStudentId(studentId);
        return Results.success(list);
    }

    @ApiOperation("创建成绩")
    @PostMapping
    public Results createScore(@RequestBody Score score) {
        boolean save = scoreService.save(score);
        return Results.success(save);
    }

    @ApiOperation("更新成绩")
    @PutMapping
    public Results updateScore(@RequestBody Score score) {
        boolean update = scoreService.updateById(score);
        return Results.success(update);
    }

    @ApiOperation("删除成绩")
    @DeleteMapping("/{id}")
    public Results deleteScore(@PathVariable Long id) {
        scoreService.removeById(id);
        return Results.success();
    }
}
